package com.rceeslca.modules.cam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rceeslca.common.utils.Result;
import com.rceeslca.modules.cam.entity.CamCourse;
import com.rceeslca.modules.cam.param.PageQueryParam;
import com.rceeslca.modules.cam.service.CamCourseService;
import com.rceeslca.modules.cam.vo.CamCourseVo;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程
 */
@Api(tags="课程")
@AllArgsConstructor
@RestController
@RequestMapping("/cam/course")
public class CamCourseController {

    @Autowired
    private CamCourseService courseService;


    /**
     * 创建
     * @param course 课程
     */
    @PostMapping("create")
    public Result createCourse(@RequestBody CamCourse course) {

        courseService.createCourse(course);

        return new Result();
    }


    /**
     * 删除
     * @param course 课程
     */
    @DeleteMapping("delete")
    public Result deleteCourse(@RequestBody CamCourse course) {

        courseService.deleteCourse(course);

        return new Result();
    }


    /**
     * 更改
     * @param course 课程
     */
    @PutMapping("update")
    public Result updateCourse(@RequestBody CamCourse course) {

        courseService.updateCourse(course);

        return new Result();
    }


    /**
     * 分页查询
     * @param param 条件参数
     */
    @PostMapping("pageList")
    public Result<IPage<CamCourseVo>> pageList(@RequestBody PageQueryParam<CamCourseVo> param) {

        Page<CamCourseVo> page = new Page<>(param.getPageNum(),param.getPageSize());
        IPage<CamCourseVo> iPage = courseService.pageList(page,param.getQuery());

        return new Result<IPage<CamCourseVo>>().ok(iPage);
    }


    /**
     * 列展示
     * @param param 条件参数
     */
    @PostMapping("getList")
    public Result<List<CamCourseVo>> getList(@RequestBody CamCourseVo param) {

        List<CamCourseVo> dataList = courseService.listCourse(param);

        return new Result<List<CamCourseVo>>().ok(dataList);
    }

}
